package com.roncoo.education.system.dao.impl;

import cn.hutool.core.collection.CollUtil;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.roncoo.education.common.core.base.Page;
import com.roncoo.education.common.core.base.PageUtil;
import com.roncoo.education.common.core.tools.IdWorker;
import com.roncoo.education.system.dao.MinioUploadingDao;
import com.roncoo.education.system.dao.impl.mapper.MinioUploadingMapper;
import com.roncoo.education.system.dao.impl.mapper.entity.MinioUploading;
import com.roncoo.education.system.dao.impl.mapper.entity.MinioUploadingExample;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 系统配置 服务实现类
 *
 * @author wujing
 * @date 2022-08-25
 */
@Repository
@RequiredArgsConstructor
public class MinioUploadingDaoImpl implements MinioUploadingDao {

    @NotNull
    private final MinioUploadingMapper mapper;

    @Override
    public int save(MinioUploading record) {
        if (StringUtils.isEmpty(record.getId())) {
            return 0;
        }
        return this.mapper.insertSelective(record);
    }

    @Override
    public int deleteById(String id) {
        return this.mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateById(MinioUploading record) {
        return this.mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public MinioUploading getById(String id) {
        return this.mapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<MinioUploading> page(int pageCurrent, int pageSize, MinioUploadingExample example) {
        int count = this.mapper.countByExample(example);
        pageSize = PageUtil.checkPageSize(pageSize);
        pageCurrent = PageUtil.checkPageCurrent(count, pageSize, pageCurrent);
        int totalPage = PageUtil.countTotalPage(count, pageSize);
        example.setLimitStart(PageUtil.countOffset(pageCurrent, pageSize));
        example.setPageSize(pageSize);
        return new Page<>(count, totalPage, pageCurrent, pageSize, this.mapper.selectByExample(example));
    }

    @Override
    public List<MinioUploading> listByExample(MinioUploadingExample example) {
        return this.mapper.selectByExample(example);
    }

    @Override
    public int countByExample(MinioUploadingExample example) {
        return this.mapper.countByExample(example);
    }
}
